<style lang="scss" scoped>
    .dynamic{
      margin-top: 0.937vw;
      .title{
        font-size: 0.833vw;
        font-family: PingFang SC;
        font-weight: 400;
        color: #00D1E3;
        opacity: 1;
        margin-bottom: 0.625vw;
        line-height: 1.145vw;
      }
      .box{
        width: 23.75vw;
        padding-bottom:0.312vw;
        .th{
          width: 23.75vw;
          height: 1.98vw;
          background: rgba(4, 146, 164, 0.1);
          opacity: 1;
          span{
            width: 5.729vw;
            font-size: 0.677vw;
            font-family: PingFang SC;
            font-weight: 400;
            line-height: 1.98vw;
            color: #00D1E3;
            text-align: center;
            display: inline-block;
          }
          span:first-child{
            width: 4.48vw;
          }
          span:nth-child(2){
            width: 7.812vw;
          }
        }
        .body{
          height: 11.98vw;
          overflow-y: hidden;
          .lis{
            position: relative;

            .li{
              display: flex;
              align-items: center;
              height: 2.396vw;
              span{
                width: 5.73vw;
                display: flex;
                align-items: center;
                justify-content: center;
                font-family: PingFang SC;
                font-weight: 400;
                line-height: 1.98vw;
                text-align: center;
                display: inline-block;
                font-size: 0.625vw;
                color: #E3E3E3;
                line-height:  2.396vw;
                opacity: 1;
              }
              span:first-child{
                width: 4.48vw;
              }
              span:nth-child(2){
                width: 7.812vw;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
              }
              span:last-child{
                display: flex;
                justify-content: center;
                align-items: center;
                .action{
                  width: 2.19vw;
                  height: 0.937vw;
                  border: 0.052vw solid #40A0FC;
                  opacity: 1;
                  font-size: 0.469vw;
                  font-family: PingFang SC;
                  font-weight: 400;
                  line-height: 0.937vw;
                  color: #40A0FC;
                  opacity: 1;
                  cursor: pointer;
                }
              }
            }
          }
          .stopTrans{
            transition: bottom 2s ease;
          }
        }
        .body::-webkit-scrollbar {display:none}
      }
    }
</style>
<template>
  <div class="dynamic">
    <div class="title">动态管理提示</div>
    <div class="box bot_s">
      <div class="th">
        <span>设备号</span>
        <span>地址</span>
        <span>类型</span>
        <span>操作</span>
      </div>
      <div class="body" @mouseenter="deferTran" @mouseleave="continueTran">
        <div class="lis" :style="{bottom}" :class="stopTransDynamicFlag? 'stopTrans': ''" ref="lis">
          <div class="li" v-for="item in dynamicData">
            <span>{{item.deviceCode}}</span>
            <span>{{item.address}}</span>
            <span>{{item.typeName}}</span>
            <span><div class="action" @click="faultDeal(item)">处理</div></span>
          </div>
        </div>
      </div>
    </div>
  </div>

</template>

<script>
import { mapGetters } from "vuex";
import moment from 'moment'
import {listRealTimeFaultReport,faultDeal
} from "@/api/screem";
import padleftcurrent from './padleftcurrent.vue'
export default {
  name: "screem",
  data() {
    return {
      initTimer: null,
      frontData: {},
      dynamicData: [],
      dynamicDataOrigin: [],
      stopTransDynamicFlag: true,
      dynamicDataIndex: 0,
      dynamicTimer:null,
      dynamicTmp: [],
    };
  },
  created() {
    //document.querySelector('#app').style.overflow = 'auto'
   this.pullInit()
  },
  computed: {
    bottom() {
      return this.dynamicDataIndex * 2.396 + "vw"; //定义移动的单元高度
    }
  },
  mounted() {
    this.transDynamic()
  },
  props: [],
  methods: {
    faultDeal(item) {
      faultDeal({deviceCode:item.deviceCode})
        .then(res => {
          this.$message({
            type: "success",
            message: "处理成功!"
          });
        })
    },
    deferTran() {
      this.stopTransDynamicFlag = false
    },
    continueTran() {
      this.stopTransDynamicFlag = true
    },
    pullInit() {
      this.init()
      this.initTimer = setInterval(() => {
        this.init()
      }, 60000)
    },
    transDynamic() {
      this.dynamicTimer = setInterval(_ => {
        if (!this.stopTransDynamicFlag) {
          return false
        }
        //自定义滚动 出勤率
        if (this.dynamicDataIndex < 10 ) {
          this.dynamicDataIndex += 1;
        } else {
          this.stopTransDynamicFlag = false
          if (this.dynamicTmp.length) {
            this.dynamicTmp.forEach(i => {
              this.dynamicData.splice(-5,0 ,i)
            })
            this.dynamicTmp = []
          }
          setTimeout(() => {
            this.dynamicDataIndex = 0;
            setTimeout(() => {
              this.stopTransDynamicFlag = true
            }, 1000)
          }, 1000)
        }
      }, 3000);
    },
    init() {
      listRealTimeFaultReport()
        .then(res => {
          if(!this.stopTransDynamicFlag) {
            return
          }
          if (this.dynamicData.length > 100) {
            this.dynamicDataOrigin = (res.data || [])
            this.dynamicData = this.dynamicDataOrigin.concat(this.dynamicDataOrigin.slice(0,5))
            return
          }

          if (this.dynamicDataOrigin.length === 0) {
            this.dynamicDataOrigin = (res.data || [])
          } else {
            this.dynamicTmp = (res.data || []).filter(item => item.id > this.dynamicData[this.dynamicData.length - 6].id)
          }
          if (this.dynamicData.length === 0) {
            this.dynamicData = this.dynamicDataOrigin.concat(this.dynamicDataOrigin.slice(0,5)).concat(this.dynamicDataOrigin.slice(0,5))
          }
        })
    }
  }
};
</script>


